<?php
define("FANWE_REQUIRE",true);


if (isset($_REQUEST['cstype']) && $_REQUEST['cstype'] == 1) {
    require '../../system/wap_init.php';
} else {
    require '../../system/pc_init.php';
}

fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
require  APP_ROOT_PATH.'system/template/template.php';
$tmpl = new AppTemplate;

$GLOBALS['tmpl']->cache_dir      = APP_ROOT_PATH . 'public/runtime/baimei/tpl_caches';
$GLOBALS['tmpl']->compile_dir    = APP_ROOT_PATH . 'public/runtime/baimei/tpl_compiled';
$GLOBALS['tmpl']->template_dir   = APP_ROOT_PATH . 'frontEnd/baimei/view';
$GLOBALS['tmpl']->assign("TMPL_REAL",APP_ROOT_PATH."frontEnd/baimei");
$tmpl_path = get_domain().APP_ROOT;
$GLOBALS['tmpl']->assign("TMPL",$tmpl_path);

// $jstmpl_path = get_domain().APP_ROOT."/baimei/";
// $GLOBALS['tmpl']->assign("JSTMPL",$jstmpl_path);

fanwe_require(APP_ROOT_PATH.'frontEnd/baimei/lib/core/common.php');
fanwe_require(APP_ROOT_PATH.'mapi/lib/core/common.php');

filter_injection($_REQUEST);


//会员自动登录及输出
$cookie_uid = es_cookie::get("user_id")?es_cookie::get("user_id"):'';
$cookie_upwd = es_cookie::get("user_pwd")?es_cookie::get("user_pwd"):'';
$promoter_id = es_cookie::get("promoter_id")?es_cookie::get("promoter_id"):'';

if($cookie_uid!=''&&$cookie_upwd!=''&&!es_session::get("user_info"))
{
    //fanwe_require(APP_ROOT_PATH."system/libs/user.php");	
	fanwe_require(APP_ROOT_PATH."mapi/lib/base.action.php");
	fanwe_require(APP_ROOT_PATH."mapi/bm_index/login.action.php");	
    $login = new loginCModule();
    $login->auto_do_login_user($cookie_uid,$cookie_upwd,$promoter_id);
}

//用户信息
global $user_info;
$user_info = es_session::get('user_info');

$GLOBALS['tmpl']->assign("user_info", $user_info);
global $promoter_info;
$promoter_info=es_session::get('promoter_info');

global $act_list;
$act_list=es_session::get('act_list');
if (!$act_list) {
	//$role_list=json_decode($promoter_info['role_list'],true);
	$role_list = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."bm_role where id=".intval($promoter_info['bm_role_id']));
	$role_list=unserialize($role_list['role_list']);
	$act_list=array();
	foreach ($role_list as $k=>$v){
		$act_list[]=$v['action'];
	}
	es_session::set("act_list",$act_list);
}

$GLOBALS['tmpl']->assign("act_list", $act_list);
$GLOBALS['tmpl']->assign("promoter_info", $promoter_info);
$_REQUEST['ctl'] = filter_ma_request($_REQUEST['ctl']);
$_REQUEST['act'] = filter_ma_request($_REQUEST['act']);

$search = array("../","\n","\r","\t","\r\n","'","<",">","\"","%","\\",".","/");
$itype = str_replace($search,"",$_REQUEST['itype']);

$class = strtolower(strim($_REQUEST['ctl']))?strtolower(strim($_REQUEST['ctl'])):"index";
$class_name = $class;
$lib = $itype?$itype:'bm_index';

if($lib=='lib'){

    fanwe_require(APP_ROOT_PATH."mapi/lib/base.action.php");
    @fanwe_require(APP_ROOT_PATH."mapi/lib/".$class.".action.php");
    $class=$class.'Module';
}else{

    fanwe_require(APP_ROOT_PATH."mapi/lib/base.action.php");
    fanwe_require(APP_ROOT_PATH."mapi/".$lib."/base.action.php");
    fanwe_require(APP_ROOT_PATH."mapi/".$lib."/".$class.".action.php");
    $class=$class.'CModule';
}

$act = strtolower(strim($_REQUEST['act']))?strtolower(strim($_REQUEST['act'])):"index";
$GLOBALS['tmpl']->assign("ctl",$class_name);
$GLOBALS['tmpl']->assign("act",$act);

if(class_exists($class)){
    $obj = new $class;
    if(method_exists($obj, $act)){
        $obj->$act();
    }
    else{
        $error["errcode "] = 10006;
        $error["errmsg "] = "接口方法不存在";
        ajax_return($error);
    }
}
else{
    $error["errcode "] = 10005;
    $error["errmsg "] = "接口不存在";
    ajax_return($error);
}

?>